using UnityEngine;
using Super;
using UnityEngine.UI;
using TMPro;
using System.Collections.Generic;
using System;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;

namespace Super.Sample
{
    public class FxiedController : MonoBehaviour
    {
        public VirtualItemList itemList;
        public int num = 10;
        public bool isCenter = true;

        [Button("OnBtnClick")]
        public string btnStr = "初始化";

        [Button("OnBtn1Click")]
        public string btnStr1 = "增加";

        [Button("OnBtn2Click")]
        public string btnStra = "减少";

        [Button("OnBtn3Click")]
        public string btnStr3 = "刷新";

        [Button("OnBtn4Click")]
        public string btnStr4 = "跳转";

        [Button("OnBtn5Click")]
        public string btnStr5 = "触发器重置";

        public void OnBtnClick()
        {
            itemList.SetItemNum(num, OnItemLoad);
        }

        public void OnBtn1Click()
        {
            itemList.ModifyItemCount(ItemCountMode.Add, num);
        }

        public void OnBtn2Click()
        {
            itemList.ModifyItemCount(ItemCountMode.Reduce, num);
        }
        public void OnBtn3Click()
        {
            itemList.Refresh();
        }

        public void OnBtn4Click()
        {
            itemList.JumpToItem(num, isCenter);
        }

        public void OnBtn5Click()
        {
            itemList.ResetTriggerState();
        }

        public void Start()
        {
            itemList.SetItemNum(num, OnItemLoad);
            itemList.SetScrollTrigger(OnScrollTop, OnScrollBottom);
        }

        public void Update()
        {
            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                OnBtn1Click();
            }

            if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                OnBtn2Click();
            }
        }

        public virtual void OnItemLoad(Transform tf, int index)
        {
            tf.GetChildComponent<TextMeshProUGUI>("Text").text = index.ToString();
            tf.OnClick("Button", index, OnItemClick);
        }

        public virtual void OnItemClick(int index)
        {
            Transform tf = itemList.GetItem(index);
            tf.GetChildComponent<TextMeshProUGUI>("Text").text = "点击了" + index.ToString();
        }

        public void OnScrollTop()
        {
            Debug.Log("scroll to top");
        }

        public void OnScrollBottom()
        {
            Debug.Log("scroll to bottom");
        }
    }
}



